package bid.yanhj.yanhaijiang.hello_word;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

/**
 * 新手引导页
 */
public class GuideActivity extends Activity implements View.OnTouchListener {

    private final int[] resIds = {R.mipmap.guide1,R.mipmap.guide2,R.mipmap.guide3};

    private ViewPager viewPager = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.antivity_guide);

        initView();

    }

    public void initView() {
        viewPager = this.<ViewPager>findViewById(R.id.viewPager);

        viewPager.setAdapter(new PagerAdapter() {
            @Override
            public int getCount() {
                return resIds.length;
            }

            @Override
            public boolean isViewFromObject(View view, Object object) {
                return view == object;
            }

            @Override
            public Object instantiateItem(ViewGroup container, int position) {
                // 动态创建图片
                ImageView imageView = new ImageView(GuideActivity.this);
                imageView.setBackgroundResource(resIds[position]);
                imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);

                container.addView(imageView);
                return imageView;
            }

            @Override
            public void destroyItem(ViewGroup container, int position, Object object) {
                container.removeView((View) object);
            }
        });

        // 事件
        viewPager.setOnTouchListener(this);
    }

    @Override
    public boolean onTouch(View v, MotionEvent event) {
        return false;
    }
}
